<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>节流函数</title>
</head>
<body>
    
</body>
</html>

<script>
    //throttle: 节流 
    //delay: 延迟
    //callback: 回调
    //current：当前的



    export function throttle(callback,delay){
        let start = 0 // 保存第一次点击立即调用
        
        return function(){
            //它的this是谁就得让callback()中的this是谁，它接收的所有实参都直接交给callback()
            const current =Date.now()//现在时间
            if(current - start >delay){ //从第二次点击开始，需要间隔时间超过delay
                callback.apply(this.arguments)
                start = current
            }
        }
    }


</script>